<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="title" label="审核内容">
        <template slot-scope="{ row }">
          <p class="preview" @click="handlePreview(row.sysCourse)">
            {{ row.sysCourse ? row.sysCourse.title : '课程已删除' }}
          </p>
        </template>
      </el-table-column>
      <el-table-column prop="team" label="创建人">
        <template slot-scope="{ row }">
          {{ row.flowInitiateUser.userName }}
        </template>
      </el-table-column>
      <el-table-column prop="nodeName" label="节点名称"> </el-table-column>
      <el-table-column prop="approverStatus" label="审核状态">
        <template slot-scope="{ row }">
          <span class="color-info" v-if="row.approverStatus == 1">待审核</span>
          <span class="color-success" v-if="row.approverStatus == 2">
            同意</span
          >
          <span class="color-danger" v-if="row.approverStatus == 3">驳回</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建日期"> </el-table-column>
      <el-table-column label="操作" width="320">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button
              type="success"
              size="mini"
              :disabled="!row.hasOwnProperty('sysCourse')"
              @click="handlePreview(row.sysCourse)"
              >预览</el-button
            >
            <el-button
              type="primary"
              size="mini"
              :disabled="!row.hasOwnProperty('sysCourse')"
              v-if="
                !row.hasOwnProperty('approverStatus') || row.approverStatus == 1
              "
              @click="handleReview(row)"
              >审核</el-button
            >
            <el-button
              type="warning"
              size="mini"
              :disabled="!row.hasOwnProperty('sysCourse')"
              v-if="
                !row.hasOwnProperty('approverStatus') || row.approverStatus == 1
              "
              @click="handlePushSpecialist(row)"
              >推送专家</el-button
            >
            <el-button
              type="primary"
              size="mini"
              @click="handleAuditFlow(row)"
              :disabled="!row.hasOwnProperty('sysCourse')"
              >查看审核流程</el-button
            >
            <el-button
              type="danger"
              size="mini"
              :disabled="!row.hasOwnProperty('sysCourse')"
              v-if="row.approverStatus > 1"
              @click="handleReject(row)"
              >驳回</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { flowApiTakeBack2 } from '@/api/admin/audit/flowApi.js'
import coursePreview from '@/mixins/coursePreview'
import Bus from '@/utils/bus.js'
export default {
  mixins: [coursePreview],
  data() {
    return {
      form: {
        id: '', //流程实例
        approverStatus: '3', //审批状态，2-同意，3-不同意
      },
    }
  },
  props: ['tableData'],
  methods: {
    handleReview(v) {
      Bus.$emit('showDialogReview', v)
    },
    handleReviewHistory(v) {
      Bus.$emit('showDialogReviewHistory', v)
    },
    handlePushSpecialist(v) {
      Bus.$emit('pushSpecialist', v)
    },
    handleReviewInfo(v) {
      Bus.$emit('showDialogExpertAdvice', v)
    },
    handleAuditFlow(v) {
      this.$store.commit('SETCURCOURSE', v.sysCourse)
      Bus.$emit('showDialogAuditFlow', v)
    },
    handleReject(v) {
      let { businessKey } = v
      flowApiTakeBack2({ businessKey }).then((res) => {
        if (!res || res.data.code != 0) return
        Bus.$emit('flowRunTaskList')
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>
<style scoped lang="scss">
.preview {
  cursor: pointer;
  &:hover {
    color: var(--colorH1);
  }
}
</style>